package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 几何类型枚举
 *
 * <p>管理批注系统中各种几何图形的类型。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum GeometryType implements BaseEnum {

    // === 基础几何图形 ===
    RECTANGLE("RECTANGLE", "矩形"),
    SQUARE("SQUARE", "正方形"),
    CIRCLE("CIRCLE", "圆形"),
    ELLIPSE("ELLIPSE", "椭圆形"),
    TRIANGLE("TRIANGLE", "三角形"),

    // === 线条几何 ===
    LINE("LINE", "直线"),
    POLYLINE("POLYLINE", "折线"),
    CURVE("CURVE", "曲线"),
    BEZIER("BEZIER", "贝塞尔曲线"),

    // === 多边形几何 ===
    POLYGON("POLYGON", "多边形"),
    PENTAGON("PENTAGON", "五边形"),
    HEXAGON("HEXAGON", "六边形"),
    OCTAGON("OCTAGON", "八边形"),
    STAR("STAR", "星形"),

    // === 文本几何 ===
    TEXT_BOX("TEXT_BOX", "文本框"),
    TEXT_AREA("TEXT_AREA", "文本区域"),

    // === 标注几何 ===
    CALL("CALL", "标注"),
    BUBBLE("BUBBLE", "气泡"),

    // === 自由绘制几何 ===
    FREEHAND_RECTANGLE("FREEHAND_RECTANGLE", "手绘矩形"),
    FREEHAND_CIRCLE("FREEHAND_CIRCLE", "手绘圆形"),
    FREEHAND_POLYGON("FREEHAND_POLYGON", "手绘多边形");

    private final String code;
    private final String description;

    GeometryType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static GeometryType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Geometry type code cannot be null or empty");
        }

        for (GeometryType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown geometry type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static GeometryType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Geometry type description cannot be null or empty");
        }

        for (GeometryType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown geometry type description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}